package com.gudaomai.ekproject.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gudaomai.ekproject.common.CommonException;
import com.gudaomai.ekproject.entity.Element;
import com.gudaomai.ekproject.entity.Page;
import com.gudaomai.ekproject.entity.PageInput;
import com.gudaomai.ekproject.entity.RetEntity;
import com.gudaomai.ekproject.service.IElementService;
import com.gudaomai.ekproject.web.BaseController;

import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 画面项目 前端控制器
 * </p>
 *
 * @author zenghualu
 * @since 2017-06-26
 */
@RestController
@RequestMapping("/ekproject/element")
public class ElementController extends BaseController {


	@Autowired
	IElementService elementServ;

	/**
	 * 根据页面id获取所有的元素
	 * 
	 * @param pageId
	 * @return
	 */
	@ApiOperation(value = "根据页面id获取所有的元素")
	@RequestMapping(value = "/pageId/{id}", method = RequestMethod.GET)
	public List<Element> getByPageId(@PathVariable("id") String pageId) throws CommonException {

		// 异常已在service里面抛出
		List<Element> elements = elementServ.getElementByPageId(pageId);

		return elements;
	}
	
	/**
	 * 根据id更新页面信息
	 * TODO:jesse
	 * 1.输入值的正确性check
	 * 
	 * @param pageId
	 * @return
	 */
	@ApiOperation(value = "根据页面id获取所有的元素")
	@RequestMapping(value = "/pageId/{id}", method = RequestMethod.GET)
	public RetEntity updatePage(@RequestBody PageInput page ) {
		return null;
	}

}
